package Base.ExceptionTest;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class ThrowsTest {

    public static void method1() throws IOException {
        final File file = new File("hello.txt");
        final FileInputStream fileInputStream = new FileInputStream(file);

        int read = fileInputStream.read();
        while (read != -1){
            System.out.println((char) read); // 转字符
            read = fileInputStream.read();
        }
        fileInputStream.close();

    }

    public static void method2() throws IOException {
        method1();
    }

    // 这里已经到main函数了，无法在往上抛出异常了。只能通过try结构来解决
    public static void main(String[] args){
        try {
            method2();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
    }

}
